package com.springbootstart;

import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import java.io.File;
import java.io.IOException;
@Component
public class MyTomcat implements WebServerFactory{
    private static final Logger log = LoggerFactory.getLogger(MyTomcat.class);
    @Override
    public void createServer() {
        Tomcat tomcat = new Tomcat();
        tomcat.setPort(8888);

        try {
            String canonicalPath = new File("C:\\Users\\zyl\\zyl").getCanonicalPath();
            tomcat.addWebapp("/", canonicalPath);
            tomcat.start();
            tomcat.getServer().await();

        } catch (IOException | LifecycleException | ServletException e) {
            e.printStackTrace();
            log.error(e.getMessage(), e);
        }

    }
}
